﻿using System.Reflection;

namespace WpfAdvControls.AssemblyStarter
{
    public class AssemblyStarter
    {
        public string Name { get; set; }
        public string AssemblyFile { get; set; }
        public string ClassName { get; set; }
        public string MethodName { get; set; }
        public object[] MethodArguments { get; set; }

        public void Start()
        {
            var assembly = Assembly.LoadFrom(AssemblyFile);
            var instanceType = assembly.GetType(ClassName);
            var methodInfo = instanceType.GetMethod(MethodName);
            object instance = null;
            if (!methodInfo.IsStatic)
            {
                instance = assembly.CreateInstance(ClassName);
            }
            instanceType.InvokeMember(MethodName, BindingFlags.InvokeMethod, null, instance, MethodArguments);
        }
    }
}